<template>
    <div class="newsinfo-container">
        <!-- 大标题 -->
        <h3 class="title">{{ newsobj.title }}</h3>
        <!-- 子标题 -->
        <p class="subtitle">
            <span>发表时间:{{ newsobj.add_time | dateFormat}}</span>
            <span>点击:{{ newsobj.click }}次</span>
        </p>
        <hr />
        <!-- 内容区域 -->
        <div class="content" v-html="newsobj.content"></div>
        <!-- 评论子组件 -->
        <comment-box :infoid="this.id"></comment-box>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui';
    //导入评论子组件
    import comment from '../subcomponents/comment.vue';
    export default {
        data() {
            return {
                id: this.$route.params.id, //将URL传递的id值挂载到data上，方便以后调用
                newsobj: {} //新闻对象
            };
        },
        created() {
            this.getnewsinfo();
        },
        methods: {
            getnewsinfo() {
                this.axios.get('api/getnew/' + this.id).then(result => {
                    // console.log(result);
                    if (result.data.status === 0) {
                        this.newsobj = result.data.message[0];
                    } else {
                        Toast('加载新闻数据失败！');
                    }
                });
            }
        },
        components: {
            //用来注册子组件节点
            'comment-box': comment
        }
    };
</script>

<style lang="less">
.newsinfo-container {
    padding: 0 4px;
    .title {
        font-size: 16px;
        color: rgb(207, 15, 15);
        text-align: center;
        margin: 10px 0;
    }
    .subtitle {
        font-size: 13px;
        color: #226aff;
        display: flex;
        justify-content: space-between;
    }
    .content {
        img {
            width: 100%;
        }
    }
}
</style>